package model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Vector;

import util.GetTime;

public class MemberDAO {
	
	public static void main(String[] args){
		
		MemberDAO md = new MemberDAO();
		
//		
//		md.getBoardListPage(1, 3);
//		Member member = new Member();
//		member.setMid("ccc");
//		member.setMpass("1234");
//		member.setMname("bbbb");
//		
//		member.setMemail("aijua@naver.com");
		
//		System.out.println(md.insert(member));
		
//		System.out.println(md.countMembers());
		
	}
		
	public int insert(Member member){
		int result = 0;
		Connection conn = null;
		String sql = "insert into member (mid, mname, mpass, lvno, mbirth, memail, " +	//6
				"maddresso, maddressh, mphoneo, mphoneh, " +	//4
				"mintro, mphotoofn, mphotosfn, mregdate, " +		//4
				"mobirth, moemail, moaddresso, moaddressh, mophoneo, mophoneh, " +	//6
				"mointro, mophoto, momailing) " +	//3
				//@@ "values(?,?,?,?,cast(? as date),?,?,?,?,?,?,?,?,now(),?,?,?,?,?,?,?,?,?)";
				"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			
//			PrepareStatement parameter setting
			pstmt.setString(1, member.getMid());
			pstmt.setString(2, member.getMname());
			pstmt.setString(3, member.getMpass());
			pstmt.setInt(4, member.getLvno());
			pstmt.setString(5, member.getMbirth());
			pstmt.setString(6, member.getMemail());
			pstmt.setString(7, member.getMaddresso());
			pstmt.setString(8, member.getMaddressh());
			pstmt.setString(9, member.getMphoneo());
			pstmt.setString(10, member.getMphoneh());
			pstmt.setString(11, member.getMintro());
			pstmt.setString(12, member.getMphotoofn());
			pstmt.setString(13, member.getMphotosfn());
			pstmt.setTimestamp(14, GetTime.nowTime);
			
			pstmt.setInt(15, member.getMobirth().equals("on")?1:0);
			pstmt.setInt(16, member.getMoemail().equals("on")?1:0);
			pstmt.setInt(17, member.getMoaddresso().equals("on")?1:0);//
			pstmt.setInt(18, member.getMoaddressh().equals("on")?1:0);
			pstmt.setInt(19, member.getMophoneo().equals("on")?1:0);
			pstmt.setInt(20, member.getMophoneh().equals("on")?1:0);//
			pstmt.setInt(21, member.getMointro().equals("on")?1:0);
			pstmt.setInt(22, member.getMophoto().equals("on")?1:0);
			pstmt.setInt(23, member.getMomailing().equals("on")?1:0);
				
			result = pstmt.executeUpdate();			
			
		} catch (Exception e){
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		
		return result;
	}
	
	public int delete(String mid){
		int result = 0;
		String sql = "delete from member where mid=?";
		Connection conn = null;
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, mid);
			result = pstmt.executeUpdate();
			
		} catch (Exception e){
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public int updateMpass(Member member){
		int result = 0;
		Connection conn = null;
		String sql = "update member set mpass=? where mid=?";
		
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
	
			pstmt.setString(1, member.getMpass());
			pstmt.setString(2, member.getMid());
				
			result = pstmt.executeUpdate();			
			
		} catch (Exception e){
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}		
		return result;		
	}
	
	public int updateLvno(Member member){
		
		int result = 0;
		Connection conn = null;
		String sql = "update member set lvno=? where mid=?";
		
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
	
			pstmt.setInt(1, member.getLvno());
			pstmt.setString(2, member.getMid());
				
			result = pstmt.executeUpdate();			
			
		} catch (Exception e){
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}		
		return result;		
	}
	
	public int updateInfos(Member member){
		int result = 0;
		Connection conn = null;
		String sql = "update member set " +
				"memail=?, maddresso=?, maddressh=?," +
				"mphoneo=?,mphoneh=?, mintro=? " +
				"where mid=?";
		
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
	
			pstmt.setString(1, member.getMemail());
			pstmt.setString(2, member.getMaddresso());
			pstmt.setString(3, member.getMaddressh());
			pstmt.setString(4, member.getMphoneo());
			pstmt.setString(5, member.getMphoneh());
			pstmt.setString(6, member.getMintro());
			pstmt.setString(7, member.getMid());
				
			result = pstmt.executeUpdate();			
			
		} catch (Exception e){
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}		
		return result;		
	}
	
	public int updatePhoto(Member member){
		int result = 0;
		Connection conn = null;
		String sql = "update member set " +
				"mphotoofn=?, mphotosfn=? " +
				"where mid=?";
		
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
	
			pstmt.setString(1, member.getMphotoofn());
			pstmt.setString(2, member.getMphotosfn());
			pstmt.setString(3, member.getMid());
				
			result = pstmt.executeUpdate();			
			
		} catch (Exception e){
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}		
		return result;		
	}
	
	public int updateIsOpened(Member member){
		int result = 0;
		Connection conn = null;
		String sql = "update member set " +
				"mobirth=?, moemail=?, moaddresso=?, moaddressh=?, mophoneo=?, mophoneh=?," +
				"mointro=?, mophoto=?, momailing=? "+
				"where mid=?";
		
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
	
			pstmt.setInt(1, member.getMobirth().equals("on")?1:0);
			pstmt.setInt(2, member.getMoemail().equals("on")?1:0);
			pstmt.setInt(3, member.getMoaddresso().equals("on")?1:0);
			pstmt.setInt(4, member.getMoaddressh().equals("on")?1:0);
			pstmt.setInt(5, member.getMophoneo().equals("on")?1:0);
			pstmt.setInt(6, member.getMophoneh().equals("on")?1:0);
			pstmt.setInt(7, member.getMointro().equals("on")?1:0);
			pstmt.setInt(8, member.getMophoto().equals("on")?1:0);
			pstmt.setInt(9, member.getMomailing().equals("on")?1:0);
			pstmt.setString(10, member.getMid());
			result = pstmt.executeUpdate();			
			
		} catch (Exception e){
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}		
		return result;		
	}
	
	public int updateAll(Member member){
		Connection conn = null;
		int result=0;
		
		conn = ConnectionManager.getConnection();
		result = updateMpass(member);
		result = updateLvno(member);
		result = updatePhoto(member);
		result = updateInfos(member);
		result = updateIsOpened(member);		
		
		return result;
	}
	
	public int countMembers(){
		int result = 0;
		Connection conn = null;
		String sql = "select count(mid) from member";
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				result = rs.getInt(1);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public Vector<MemberCommunity> getMemberCommunities(Member member){
		Vector<MemberCommunity> v = new Vector<MemberCommunity>();
		Connection conn = null;
		String sql = "select mid, cono, lvno, mcnick, mcregdate from membercommunity where mid=?";
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			
			pstmt.setString(1, member.getMid());
			ResultSet rs = pstmt.executeQuery();
			
			while(rs.next()){
				MemberCommunity mc = new MemberCommunity();
				mc.setMid(rs.getString("mid"));
				mc.setCono(rs.getInt("cono"));
				mc.setLvno(rs.getInt("lvno"));
				mc.setMcnick(rs.getString("mcnick"));
				mc.setMcregdate(rs.getDate("mcregdate"));
				v.add(mc);
			}
			
		} catch (Exception e){
			e.printStackTrace();			
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}		
		return v;
	}
	
	/**
	 *조성일 추가
	 *당일 가입자 리스트 추출 메소드
	 *당일 가입자의 목록을 취득한다. 
	 * */
	public Vector<Member> getBoardListPage( long currentPage, long rowsPerPage){
		
		Vector<Member> vector = new Vector<Member>();
		Connection conn = ConnectionManager.getConnection();
		String sql = 
			"SELECT T1.* FROM 																						"+
			"(																										"+
			"	SELECT T.*,(@rownum:=@rownum+1) rownum FROM															"+
			"	(																									"+
			"		SELECT MEMBER.*,(@rownum:=0) rnum																"+
			"		FROM MEMBER 																					"+
			"		WHERE DATE_FORMAT(mregdate,'%Y-%m-%d') < DATE_FORMAT(now(),'%Y-%m-%d') ORDER BY mregdate desc	"+
			"	) T																									"+
			") T1	limit "+rowsPerPage*(currentPage-1)+","+rowsPerPage;																					
			
			
		
		try {
			///////////////////////////////////////////////
			Statement stmt = conn.createStatement();
			ResultSet rs = stmt.executeQuery(sql);
		
			
			
			while(rs.next()) {
				
				Member m = new Member();
				m.setMid(rs.getString("mid"));
				m.setMname(rs.getString("mname"));
				m.setMpass(rs.getString("mpass"));
				m.setLvno(rs.getInt("lvno"));
				m.setMbirth(rs.getString("mbirth"));
				m.setMemail(rs.getString("memail"));
				m.setMaddresso(rs.getString("maddresso"));
				m.setMaddressh(rs.getString("maddressh"));
				m.setMphoneo(rs.getString("mphoneo"));
				m.setMphoneh(rs.getString("mphoneh"));
				m.setMintro(rs.getString("mintro"));
				m.setMphotoofn(rs.getString("mphotoofn"));
				m.setMphotosfn(rs.getString("mphotosfn"));
				m.setMregdate(rs.getString("mregdate").substring(0,11));
				m.setMobirth(rs.getInt("mobirth")==1?"on":null);
				m.setMoemail(rs.getInt("moemail")==1?"on":null);
				m.setMoaddresso(rs.getInt("moaddresso")==1?"on":null);
				m.setMoaddressh(rs.getInt("moaddressh")==1?"on":null);
				m.setMophoneo(rs.getInt("mophoneo")==1?"on":null);
				m.setMophoneh(rs.getInt("mophoneh")==1?"on":null);
				m.setMointro(rs.getInt("mointro")==1?"on":null);
				m.setMophoto(rs.getInt("mophoto")==1?"on":null);
				m.setMomailing(rs.getInt("momailing")==1?"on":null);
				vector.add(m);
			}
			rs.close();
			stmt.close();
			///////////////////////////////////////////////
		} catch(Exception e) {
			e.printStackTrace();
		} finally {
			if(conn!=null) try { conn.close(); } catch(Exception e) {}
		}
		return vector;
	}
	
	
	public int getTotalRows(){
		int result = 0;
		Connection conn = null;
		String sql =
		"SELECT COUNT(*)														"+
		"FROM MEMBER 															"+
		"WHERE DATE_FORMAT(mregdate,'%Y-%m-%d') < DATE_FORMAT(now(),'%Y-%m-%d')	";
		
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				result = rs.getInt(1);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		return result;
	}
	
	
	
	/**
	 * 2007.5.9 추가 메소드
	 * */
	
	public int getMemberLogin(String mid, String mpass){
		
		String sql = "select mpass,lvno from member where mid=?";
		Connection conn = null;
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, mid);
			ResultSet rs = pstmt.executeQuery();
			
			while(rs.next()){
				String pw = rs.getString("mpass");
				int lv = rs.getInt("lvno");
				if(pw.equals(mpass)){
					if(lv==9) {
						return 3;					
					} else return 2; 
				} else return 1;	
			}			
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		
		return 0;
	}
	
	public Vector getMembers(){
		Vector<Member> v = new Vector<Member>();
		String sql = "select mid, mpass, mname from member";
		Connection conn = null;
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				Member m = new Member();
				m.setMid(rs.getString("mid"));
				m.setMpass(rs.getString("mpass"));
				m.setMname(rs.getString("mname"));
				v.add(m);
			}
		} catch (Exception e) {
			e.printStackTrace();			
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		
		return v;
	}
	
	
	
	
	/**
	 * 멤버 검색 메소드 (by Mid) 2007.05.09
	 * */

	public Member getMemberByMid(String mid){
		Member m = new Member();
		String sql = "select mid, mname, mpass, lvno, mbirth, memail," +
				"maddresso, maddressh, mphoneo, mphoneh, " +
				"mintro, mintro, mphotoofn, mphotosfn, mregdate, " +
				"mobirth, moemail, moaddresso, moaddressh, mophoneo, mophoneh, mointro, mophoto, momailing " +
				"from member where mid=?";
		Connection conn = null;
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, mid);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				m.setMid(rs.getString("mid"));
				m.setMname(rs.getString("mname"));
				m.setMpass(rs.getString("mpass"));
				m.setLvno(rs.getInt("lvno"));
				m.setMbirth(rs.getString("mbirth"));
				m.setMemail(rs.getString("memail"));
				m.setMaddresso(rs.getString("maddresso"));
				m.setMaddressh(rs.getString("maddressh"));
				m.setMphoneo(rs.getString("mphoneo"));
				m.setMphoneh(rs.getString("mphoneh"));
				m.setMintro(rs.getString("mintro"));
				m.setMphotoofn(rs.getString("mphotoofn"));
				m.setMphotosfn(rs.getString("mphotosfn"));
				m.setMregdate(rs.getString("mregdate"));
				
				m.setMobirth(rs.getInt("mobirth")==1?"on":null);
				m.setMoemail(rs.getInt("moemail")==1?"on":null);
				m.setMoaddresso(rs.getInt("moaddresso")==1?"on":null);
				m.setMoaddressh(rs.getInt("moaddressh")==1?"on":null);
				m.setMophoneo(rs.getInt("mophoneo")==1?"on":null);
				m.setMophoneh(rs.getInt("mophoneh")==1?"on":null);
				m.setMointro(rs.getInt("mointro")==1?"on":null);
				m.setMophoto(rs.getInt("mophoto")==1?"on":null);
				m.setMomailing(rs.getInt("momailing")==1?"on":null);
			}
		} catch (Exception e) {
			e.printStackTrace();			
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		
		return m;
	}
	
	public Vector<Member> getMemberById(String mid){
		
		Vector<Member> vector = new Vector<Member>();
		Member m ;
		
		String sql = "select mid, mname, mpass, lvno, mbirth, memail," +
				"maddresso, maddressh, mphoneo, mphoneh, " +
				"mintro, mintro, mphotoofn, mphotosfn, mregdate, " +
				"mobirth, moemail, moaddresso, moaddressh, mophoneo, mophoneh, mointro, mophoto, momailing " +
				"from member where mid=?";
		Connection conn = null;
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, mid);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				m = new Member();
				m.setMid(rs.getString("mid"));
				m.setMname(rs.getString("mname"));
				m.setMpass(rs.getString("mpass"));
				m.setLvno(rs.getInt("lvno"));
				m.setMbirth(rs.getString("mbirth"));
				m.setMemail(rs.getString("memail"));
				m.setMaddresso(rs.getString("maddresso"));
				m.setMaddressh(rs.getString("maddressh"));
				m.setMphoneo(rs.getString("mphoneo"));
				m.setMphoneh(rs.getString("mphoneh"));
				m.setMintro(rs.getString("mintro"));
				m.setMphotoofn(rs.getString("mphotoofn"));
				m.setMphotosfn(rs.getString("mphotosfn"));
				m.setMregdate(rs.getString("mregdate"));
				
				m.setMobirth(rs.getInt("mobirth")==1?"on":null);
				m.setMoemail(rs.getInt("moemail")==1?"on":null);
				m.setMoaddresso(rs.getInt("moaddresso")==1?"on":null);
				m.setMoaddressh(rs.getInt("moaddressh")==1?"on":null);
				m.setMophoneo(rs.getInt("mophoneo")==1?"on":null);
				m.setMophoneh(rs.getInt("mophoneh")==1?"on":null);
				m.setMointro(rs.getInt("mointro")==1?"on":null);
				m.setMophoto(rs.getInt("mophoto")==1?"on":null);
				m.setMomailing(rs.getInt("momailing")==1?"on":null);
				
				vector.add(m);
			}
		} catch (Exception e) {
			e.printStackTrace();			
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		
		return vector;
	}
	
	public Vector<Member> getMemberByName(String mname){
		
		Vector<Member> vector = new Vector<Member>();
		Member m ;
		
		String sql = "select mid, mname, mpass, lvno, mbirth, memail," +
				"maddresso, maddressh, mphoneo, mphoneh, " +
				"mintro, mintro, mphotoofn, mphotosfn, mregdate, " +
				"mobirth, moemail, moaddresso, moaddressh, mophoneo, mophoneh, mointro, mophoto, momailing " +
				"from member where mname=?";
		Connection conn = null;
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, mname);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				m = new Member();
				m.setMid(rs.getString("mid"));
				m.setMname(rs.getString("mname"));
				m.setMpass(rs.getString("mpass"));
				m.setLvno(rs.getInt("lvno"));
				m.setMbirth(rs.getString("mbirth"));
				m.setMemail(rs.getString("memail"));
				m.setMaddresso(rs.getString("maddresso"));
				m.setMaddressh(rs.getString("maddressh"));
				m.setMphoneo(rs.getString("mphoneo"));
				m.setMphoneh(rs.getString("mphoneh"));
				m.setMintro(rs.getString("mintro"));
				m.setMphotoofn(rs.getString("mphotoofn"));
				m.setMphotosfn(rs.getString("mphotosfn"));
				m.setMregdate(rs.getString("mregdate"));
				
				m.setMobirth(rs.getInt("mobirth")==1?"on":null);
				m.setMoemail(rs.getInt("moemail")==1?"on":null);
				m.setMoaddresso(rs.getInt("moaddresso")==1?"on":null);
				m.setMoaddressh(rs.getInt("moaddressh")==1?"on":null);
				m.setMophoneo(rs.getInt("mophoneo")==1?"on":null);
				m.setMophoneh(rs.getInt("mophoneh")==1?"on":null);
				m.setMointro(rs.getInt("mointro")==1?"on":null);
				m.setMophoto(rs.getInt("mophoto")==1?"on":null);
				m.setMomailing(rs.getInt("momailing")==1?"on":null);
				
				vector.add(m);
			}
		} catch (Exception e) {
			e.printStackTrace();			
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		
		return vector;
	}
	
	/**
	 * 이름을 이용한 아이디 검색
	 * */	
	public ArrayList getMembersByMname(String mname){
		ArrayList<String> mnames = new ArrayList<String>();		
		String sql = "select mid from member where mname=?";
		Connection conn = null;
		try{
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, mname);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				mnames.add(rs.getString(1));
			}			
			
		} catch(Exception e){
			try {
				conn.close();
			} catch (SQLException e1) {			
				e1.printStackTrace();
			}
		}
		
		return mnames;
	}
	
	/**
	 * 이메일을 이용한 패스워드 검색 
	 * */
	public String getMembersByMemail(String mid, String memail){
		String data = null;		
		String sql = "select mpass from member where mid=? and memail=?";
		Connection conn = null;
		try{
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, mid);
			pstmt.setString(2, memail);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				data = rs.getString(1);			
			}
			
		} catch(Exception e){
			try {
				conn.close();
			} catch (SQLException e1) {			
				e1.printStackTrace();
			}
		}		
		return data;
	}
	
	/**
	 * 레벨별 멤버 추출(Vector) 2007.05.09
	 * */	
	public Vector getMemberByLvno(int lvno){
		Vector<Member> v = new Vector<Member>();
		
		String sql = "select mid, mname, mpass, lvno, mbirth, memail," +
				"maddresso, maddressh, mphoneo, mphoneh, " +
				"mintro, mintro, mphotoofn, mphotosfn, mregdate, " +
				"mobirth, moemail, moaddresso, moaddressh, mophoneo, mophoneh, mointro, mophoto, momailing " +
				"from member where mid=?";
		Connection conn = null;
		try {
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, lvno);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				
				Member m = new Member();
				m.setMid(rs.getString("mid"));
				m.setMname(rs.getString("mname"));
				m.setMpass(rs.getString("mpass"));
				m.setLvno(rs.getInt("lvno"));
				m.setMbirth(rs.getString("mbirth"));
				m.setMemail(rs.getString("memail"));
				m.setMaddresso(rs.getString("maddresso"));
				m.setMaddressh(rs.getString("maddressh"));
				m.setMphoneo(rs.getString("mphoneo"));
				m.setMphoneh(rs.getString("mphoneh"));
				m.setMintro(rs.getString("mintro"));
				m.setMphotoofn(rs.getString("mphotoofn"));
				m.setMphotosfn(rs.getString("mphotosfn"));
				m.setMregdate(rs.getString("mregdate"));
				
				m.setMobirth(rs.getInt("mobirth")==1?"on":null);
				m.setMoemail(rs.getInt("moemail")==1?"on":null);
				m.setMoaddresso(rs.getInt("moaddresso")==1?"on":null);
				m.setMoaddressh(rs.getInt("moaddressh")==1?"on":null);
				m.setMophoneo(rs.getInt("mophoneo")==1?"on":null);
				m.setMophoneh(rs.getInt("mophoneh")==1?"on":null);
				m.setMointro(rs.getInt("mointro")==1?"on":null);
				m.setMophoto(rs.getInt("mophoto")==1?"on":null);
				m.setMomailing(rs.getInt("momailing")==1?"on":null);
				
				v.add(m);
			}
		} catch (Exception e) {
			e.printStackTrace();			
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {			
				e.printStackTrace();
			}
		}
		
		return v;
	}
	
//	public Member setMemberFormtoDAO(Member mem, MemberForm form) {
//		
//		mem.setMid(form.getMid());
//		mem.setMpass(form.getMpass());
//		mem.setMname(form.getMname());
//		mem.setLvno(1);
//		
//		String mbirth = form.getMbirth1()+"-"+form.getMbirth2()+"-"+form.getMbirth3();
//		mem.setMbirth(Date.valueOf(mbirth));
//		
//		mem.setMemail(form.getMemail());
//		/**
//		 * 다른 필드 추가
//		 * */
//		
//		mem.setMobirth(form.isMobirth()?1:0);
//		mem.setMoemail(form.isMoemail()?1:0);
//		
//		return mem;
//	}
	
	public int getMemberByLetter(String mid){
		int result = 0;
		Connection conn = null;
		String sql = "select mid from member where mid = '"+mid+"'";
		try{
			conn = ConnectionManager.getConnection();
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()){
				result++;
			}
			
		} catch (Exception e){
			try {
				conn.close();
			} catch (SQLException e1) {			
				e1.printStackTrace();
			}
		}
		return result;
	}

}
